export const state = () => ({
  authUser: null
})

export const mutations = {
  SET_USER (state, user) {
    state.authUser = user
  }
}

export const actions = {
  nuxtServerInit ({ commit }, { req }) {
    if (req.session && req.session.uname) {
      console.log('req.session.uname', req.session.uname)
      commit('SET_USER', req.session.uname)
    }
  },

  login ({commit}, data) {
    commit('SET_USER', data)
  },

  logout ({commit}) {
    commit('SET_USER', null)
  }
}
